/*******************************************************************************
Copyright (C), 2017, 3iRobotics Tech. Co., Ltd.:
File name 	: bmi055.h
Author		: Klaus
Version		: V1.0.0
Date		: 2017/3/3
Description	: IMU configuration and communication

History		:
*******************************************************************************/
#ifndef _BMI055_H_
#define _BMI055_H_

#define ACC_CHIPID        0x00
#define ACC_X_LSB         0x02
#define ACC_X_MSB         0x03
#define ACC_Y_LSB         0x04
#define ACC_Y_MSB         0x05
#define ACC_Z_LSB         0x06
#define ACC_Z_MSB         0x07
#define ACC_TEMPERATURE   0x08
#define ACC_RANGE         0x0f
#define ACC_BW            0x10
#define ACC_SFRSET        0x14
#define ACC_OFC_CTRL      0x36

#define GYRO_CHIPID       0x00
#define GYRO_X_LSB        0x02
#define GYRO_X_MSB        0x03
#define GYRO_Y_LSB        0x04
#define GYRO_Y_MSB        0x05
#define GYRO_Z_LSB        0x06
#define GYRO_Z_MSB        0x07
#define GYRO_INT_STATUS1  0x0a
#define GYRO_RANGE        0x0f
#define GYRO_BW           0x10
#define GYRO_SFRSET       0x14
#define GYRO_INT_EN0      0x15
#define GYRO_SOC          0x31
#define GYRO_FOC          0x32

#define BMI055_ACC_ADDR   0x30
#define BMI055_GYRO_ADDR  0xd0
/************************************/
#define ACC_0G_X      2048
#define ACC_1G_X      (2048+1024)
#define ACC_MINUS1G_X (2048-1024)
#define ACC_0G_Y      2048
#define ACC_1G_Y      (2048+1024)
#define ACC_MINUS1G_Y (2048-1024)
#define ACC_0G_Z      2048
#define ACC_1G_Z      (2048+1024)
#define ACC_MINUS1G_Z (2048-1024)
/****************************************/

//Acc range
/****************************************************/
/**\name  RANGE AND BANDWIDTH SELECT     */
/***************************************************/
#define BMA2x2_RANGE_2G                 (3)
/**< sets range to +/- 2G mode */
#define BMA2x2_RANGE_4G                 (5)
/**< sets range to +/- 4G mode */
#define BMA2x2_RANGE_8G                 (8)
/**< sets range to +/- 8G mode */
#define BMA2x2_RANGE_16G                (12)
/**< sets range to +/- 16G mode */

//Acc BW
#define BMA2x2_BW_7_81HZ        (0x08)
 /**< sets bandwidth to LowPass 7.81HZ  */
#define BMA2x2_BW_15_63HZ       (0x09)
/**< sets bandwidth to LowPass 15.63HZ  */
#define BMA2x2_BW_31_25HZ       (0x0A)
/**< sets bandwidth to LowPass 31.25HZ  */
#define BMA2x2_BW_62_50HZ       (0x0B)
 /**< sets bandwidth to LowPass 62.50HZ  */
#define BMA2x2_BW_125HZ         (0x0C)
 /**< sets bandwidth to LowPass 125HZ  */
#define BMA2x2_BW_250HZ         (0x0D)
/**< sets bandwidth to LowPass 250HZ  */
#define BMA2x2_BW_500HZ         (0x0E)
/**< sets bandwidth to LowPass 500HZ  */
#define BMA2x2_BW_1000HZ        (0x0F)
/**< sets bandwidth to LowPass 1000HZ  */

#define BMG160_RANGE_2000	(0x00)
#define BMG160_RANGE_1000	(0x01)
#define BMG160_RANGE_500	(0x02)
#define BMG160_RANGE_250	(0x03)
#define BMG160_RANGE_125	(0x04)

#define BMG160_BW_500_HZ	(0x01)
#define BMG160_BW_230_HZ	(0x01)
#define BMG160_BW_116_HZ	(0x02)
#define BMG160_BW_47_HZ		(0x03)
#define BMG160_BW_23_HZ		(0x04)
#define BMG160_BW_12_HZ		(0x05)
#define BMG160_BW_64_HZ		(0x06)
#define BMG160_BW_32_HZ		(0x07)




#define BMI055_INTERFACE_MODE_SPI 1
#define BMI055_INTERFACE_MODE_IIC 1





void vBMI055init(void);
int8_t cBMI055ReadSonsor(float *ax, float *ay, float *az,float *gx, float *gy, float *gz);
int8_t cBMI055ReadTemperature(float *pfTemperature);
int8_t cBMI055ReadID(uint16_t *pusIDValue);
int8_t cBMI055WriteByte(uint8_t IDAddr, uint8_t regAddr, uint8_t byteValue);
int8_t cBMI055ReadnByte(uint8_t IDAddr, uint8_t regAddr, uint8_t *pBuff, uint8_t length);

#endif
